﻿package mortal.game.scene3D.map3D.util
{
    import Message.Public.*;
    import com.fyGame.fyMap.*;
    import com.gengine.utils.*;
    import extend.language.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.map3D.AstarAnyDirection.data.*;
    import mortal.game.scene3D.map3D.sceneInfo.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.utils.*;

    public class GameMapUtil extends Object
    {
        public static var mapWidth:int;
        public static var mapHeight:int;
        public static var tileWidth:int;
        public static var tileHeight:int;
        public static var tileXNum:int;
        public static var tileYNum:int;
        private static var _curMapState:MapState;
        private static var _directionMap:Dictionary = new Dictionary();
        public static var _isCanMoveOnClickMap:Boolean = true;

        public function GameMapUtil()
        {
            return;
        }// end function

        public static function get curMapState() : MapState
        {
            var _loc_1:* = new MapState();
            _curMapState = new MapState();
            return _curMapState || _loc_1;
        }// end function

        public static function init(param1:FyMapInfo) : void
        {
            mapHeight = param1.gridHeight;
            mapWidth = param1.gridWidth;
            tileHeight = param1.pieceHeight;
            tileWidth = param1.pieceWidth;
            param1.gridYNum = mapHeight / tileHeight;
            param1.gridXNum = mapWidth / tileWidth;
            tileXNum = param1.gridXNum;
            tileYNum = param1.gridYNum;
            MapVague.instance.hasLoaedMapData = true;
            return;
        }// end function

        public static function getDirectionByPoint(param1:Point, param2:Point) : int
        {
            return getDirectionByXY(param1.x, param1.y, param2.x, param2.y);
        }// end function

        public static function getDirectionBySPoint(param1:SPoint, param2:SPoint) : int
        {
            return getDirectionByXY(param1.x, param1.y, param2.x, param2.y);
        }// end function

        public static function getDirectionByXY(param1:int, param2:int, param3:int, param4:int) : int
        {
            return getDirectionByRadians(MathUitl.getRadiansByXY(param1, param2, param3, param4));
        }// end function

        public static function getDirectionByRadians(param1:Number) : int
        {
            var _loc_2:* = MathUitl.getAngle(param1);
            return _directionMap[_loc_2];
        }// end function

        public static function getTilePoint(param1:int, param2:int) : Point
        {
            var _loc_3:* = new Point();
            _loc_3.x = int(param1 / tileWidth);
            _loc_3.y = int(param2 / tileHeight);
            return _loc_3;
        }// end function

        public static function getPixelPointArray(param1:Array) : Array
        {
            var _loc_3:Point = null;
            var _loc_4:Object = null;
            var _loc_2:Array = [];
            var _loc_5:int = 0;
            while (_loc_5 < param1.length)
            {
                
                _loc_4 = param1[_loc_5];
                _loc_3 = getPixelPoint(_loc_4.x, _loc_4.y);
                _loc_2.push(_loc_3);
                _loc_5++;
            }
            return _loc_2;
        }// end function

        public static function getPixelPoint(param1:int, param2:int) : Point
        {
            var _loc_3:* = new Point();
            _loc_3.x = int(param1 * tileWidth + tileWidth * 0.5);
            _loc_3.y = int(param2 * tileHeight + tileHeight * 0.5);
            return _loc_3;
        }// end function

        public static function isPointEquals(param1:SPoint, param2:SPoint) : Boolean
        {
            return param1.x != param2.x || param1.y != param2.y;
        }// end function

        public static function getPixelPointValue(param1:int, param2:int) : int
        {
            var _loc_3:* = getTilePoint(param1, param2);
            return getPointValue(_loc_3.x, _loc_3.y);
        }// end function

        public static function getPointValue(param1:int, param2:int, param3:Array = null) : int
        {
            if (param3 == null)
            {
                param3 = Game.mapInfo.mapData;
            }
            var _loc_4:* = param3[param1];
            if (_loc_4)
            {
                if (_loc_4.length > param2)
                {
                    return _loc_4[param2];
                }
            }
            return -1;
        }// end function

        public static function isXLightGrid(param1:int, param2:int) : Boolean
        {
            return curMapState.curSceneInfo.isXLightGrid(param1, param2);
        }// end function

        public static function getPointValueByMapId(param1:int, param2:int, param3:int) : int
        {
            var _loc_4:* = MapLoader.instance.getMapData(param1);
            if (_loc_4 == null)
            {
                return -1;
            }
            var _loc_5:* = _loc_4.mapData[param2];
            if (_loc_5)
            {
                if (_loc_5.length > param3)
                {
                    return _loc_5[param3];
                }
            }
            return 0;
        }// end function

        public static function getDistancePow(param1:int, param2:int, param3:int, param4:int) : int
        {
            return Math.pow(param3 - param1, 2) + Math.pow(param4 - param2, 2);
        }// end function

        public static function getDistance(param1:int, param2:int, param3:int, param4:int) : int
        {
            return Math.sqrt(getDistancePow(param1, param2, param3, param4));
        }// end function

        public static function tilePointToLocal(param1:int, param2:int, param3:Number, param4:Number) : Point
        {
            var _loc_5:* = getPixelPoint(param1, param2);
            return pixPointToLocal(_loc_5.x, _loc_5.y, param3, param4);
        }// end function

        public static function pixPointToLocal(param1:int, param2:int, param3:Number, param4:Number) : Point
        {
            return new Point(param1 * param3, param2 * param4);
        }// end function

        public static function localToPixPoint(param1:int, param2:int, param3:Number, param4:Number) : Point
        {
            return new Point(param1 * param3, param2 * param4);
        }// end function

        public static function localToTilePoint(param1:int, param2:int, param3:Number, param4:Number) : Point
        {
            var _loc_5:* = localToPixPoint(param1, param2, param3, param4);
            return getTilePoint(_loc_5.x, _loc_5.y);
        }// end function

        public static function isMapPeaceArea(param1:SEntityId, param2:Boolean = false) : Boolean
        {
            var _loc_4:Point = null;
            var _loc_5:int = 0;
            var _loc_3:* = ThingUtil.entityUtil.getEntity(param1);
            if (_loc_3)
            {
                _loc_4 = GameMapUtil.getTilePoint(_loc_3.x2d, _loc_3.y2d);
                _loc_5 = GameMapUtil.getPointValue(_loc_4.x, _loc_4.y);
                if (MapNodeType.isAllServerSafe(_loc_5) || !param2 && MapNodeType.isSameServerSafe(_loc_5))
                {
                    return true;
                }
                return false;
            }
            return false;
        }// end function

        public static function isCopyMap(param1:int = -1) : Boolean
        {
            if (param1 == -1)
            {
                param1 = MapFileUtil.mapID;
            }
            var _loc_2:* = SceneConfig.instance.getSceneInfo(param1);
            if (_loc_2)
            {
                switch(_loc_2.sMapDefine.instanceType.__value)
                {
                    case EMapInstanceType._EMapInstanceTypeCopy:
                    {
                        return true;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return false;
        }// end function

        public static function isCrossCopyMap(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isFightWar(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isGuildWar(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isArena(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isArenaCross(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isNewBattlefield(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isCrossBossField(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isPeaceField(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isGuildMap(param1:int = -1) : Boolean
        {
            if (param1 == -1)
            {
                param1 = MapFileUtil.mapID;
            }
            var _loc_2:* = SceneConfig.instance.getSceneInfo(param1);
            if (_loc_2 == null)
            {
                return false;
            }
            return _loc_2 && _loc_2.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeGuild;
        }// end function

        public static function isVIPHook(param1:int) : Boolean
        {
            return false;
        }// end function

        public static function isBossMap(param1:int = -1) : Boolean
        {
            if (param1 == -1)
            {
                param1 = MapFileUtil.mapID;
            }
            var _loc_2:* = SceneConfig.instance.getSceneInfo(param1);
            return _loc_2 && _loc_2.sMapDefine.belong.__value == EMapBelong._EMapBelongNo;
        }// end function

        public static function isUniqueMap(param1:int = -1) : Boolean
        {
            if (param1 == -1)
            {
                param1 = MapFileUtil.mapID;
            }
            var _loc_2:* = SceneConfig.instance.getSceneInfo(param1);
            return _loc_2 && _loc_2.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeNormal;
        }// end function

        public static function isSetFightModeMap(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isEnemyMap(param1:int = -1) : Boolean
        {
            if (param1 == -1)
            {
                param1 = MapFileUtil.mapID;
            }
            var _loc_2:* = SceneConfig.instance.getSceneInfo(param1);
            return isEnemyMapByInfo(_loc_2);
        }// end function

        public static function getMapName(param1:int = -1) : String
        {
            if (param1 == -1)
            {
                param1 = MapFileUtil.mapID;
            }
            var _loc_2:* = GameMapConfig.instance.getMapInfo(param1);
            if (_loc_2 != null)
            {
                return _loc_2.name;
            }
            return "宝爷配置地图名字";
        }// end function

        public static function isEnemyMapByInfo(param1:SceneInfo) : Boolean
        {
            return false;
        }// end function

        public static function isMapSend(param1:int) : Boolean
        {
            return true;
        }// end function

        public static function isMapById(param1:int) : Boolean
        {
            return Game.sceneInfo.sMapDefine.mapId == param1;
        }// end function

        public static function isMapByCopyCode(param1:int) : Boolean
        {
            return false;
        }// end function

        public static function isCanBattle(param1:int = -1) : Boolean
        {
            return false;
        }// end function

        public static function isCrossGroupMap() : Boolean
        {
            return false;
        }// end function

        public static function isSpecialMap() : Boolean
        {
            return false;
        }// end function

        public static function isHightNumberPeopleMap() : Boolean
        {
            return false;
        }// end function

        public static function isShowGuildNameMap() : Boolean
        {
            return false;
        }// end function

        public static function isShowMainTitleMap(param1:Object) : Boolean
        {
            return false;
        }// end function

        public static function isCanNotPlayerSkillMap() : Boolean
        {
            return curMapState.isQuestionCopy;
        }// end function

        public static function isCanCallMount() : Boolean
        {
            return true;
        }// end function

        public static function isForceNameMap() : Boolean
        {
            return GameMapUtil.curMapState.isBattlefield;
        }// end function

        public static function get isForceChatMap() : Boolean
        {
            return GameMapUtil.curMapState.isBattlefield || GameMapUtil.curMapState.isEscortCopy;
        }// end function

        public static function get isInHideTitleMap() : Boolean
        {
            return curMapState.isEscortCopy || curMapState.isQuestionCopy || curMapState.isTreasureHunt;
        }// end function

        public static function get isInHideGuildMap() : Boolean
        {
            return curMapState.isEscortCopy || curMapState.isTreasureHunt;
        }// end function

        public static function get isInHideNameMap() : Boolean
        {
            return curMapState.isEscortCopy;
        }// end function

        public static function get isInHideBloodMap() : Boolean
        {
            return curMapState.isEscortCopy || curMapState.isSunbathMap;
        }// end function

        public static function get isInShowBloodMap() : Boolean
        {
            return CopyUtil.isInGuildDefenseCopy || GameMapUtil.curMapState.isWineMap;
        }// end function

        public static function get isInHideSpriteMap() : Boolean
        {
            return curMapState.isQuestionCopy || curMapState.isSunbathMap || curMapState.isWineMap;
        }// end function

        public static function isCrossNormalMap(param1:int) : Boolean
        {
            var _loc_2:* = SceneConfig.instance.getSceneInfo(param1);
            if (_loc_2 == null)
            {
                return false;
            }
            return _loc_2.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeCrossNormal;
        }// end function

        public static function set isCanMoveOnClickMap(param1:Boolean) : void
        {
            _isCanMoveOnClickMap = param1;
            return;
        }// end function

        public static function get isCanMoveOnClickMap() : Boolean
        {
            return _isCanMoveOnClickMap;
        }// end function

        public static function get unuseSkillMap() : Boolean
        {
            if (curMapState.isSunbathMap)
            {
                MsgManager.showRollTipsMsg(Language.getString(20668));
                return true;
            }
            return false;
        }// end function

        public static function shouldUseAutoPathReplaceFlyBoot(param1:int, param2:int, param3:int) : Boolean
        {
            if (Game.mapInfo != null && param1 != Game.mapInfo.mapId)
            {
                return false;
            }
            var _loc_4:* = Cache.instance.vip.freeFlyBootTimes;
            if (_loc_4 > 10 || _loc_4 == -1)
            {
                return false;
            }
            var _loc_5:* = GeomUtil.calcDistance(RolePlayer.instance.x2d, RolePlayer.instance.y2d, param2, param3);
            if (_loc_5 > 500)
            {
                return false;
            }
            return true;
        }// end function

        public static function get isDrugDisavailableMap() : Boolean
        {
            return curMapState.isTreasureHunt || curMapState.isAutoArenaMap;
        }// end function

        public static function get isInHideLevelMap() : Boolean
        {
            return curMapState.isTreasureHunt;
        }// end function

    }
}
